﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// Applicant 的摘要说明
/// </summary>
public class Applicant
{
    public int id;
    public int applyNoId_HistoryId;
    public string familyRole;
    public string marryed;
    public string workUnit;
    public string idCard;
    public float inCome;
    public bool isSecurity;

    private string ConnString = SqlHelper.ConnectionString;
    
    public Applicant()
    { }

    /// <summary>
    /// 获取成员表(原表)数据
    /// </summary>
    /// <param name="applyId"></param>
    /// <returns></returns>
    public DataSet GetApplicantById(int Id)
    {
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new SqlParameter("@ID", DbType.Int32);
        par[0].Value = Id;

        DataSet dsGetApplicant = SqlHelper.ExecuteDataset(ConnString, CommandType.StoredProcedure, 
                                                            "Select_Applicant_By_ID", par);

        return dsGetApplicant;
    }

    /// <summary>
    /// 获取成员表(历史记录表)数据
    /// </summary>
    /// <param name="applyId"></param>
    /// <returns></returns>
    public DataSet GetApplicantHistoryById(int Id)
    {
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new SqlParameter("@ID", DbType.Int32);
        par[0].Value = Id;

        DataSet dsGetApplicant = SqlHelper.ExecuteDataset(ConnString, CommandType.StoredProcedure, 
                                                            "Select_ApplicantHistory_By_ID", par);

        return dsGetApplicant;
    }

    /// <summary>
    /// 添加家庭成员表（原表）
    /// </summary>
    /// <param name="applicant"></param>
    /// <returns></returns>
    public bool AddApplicant(Applicant applicant)
    {
        SqlParameter[] par = new SqlParameter[7];
        par[0] = new SqlParameter("@ApplyNoID", DbType.Int32);
        par[0].Value = applicant.applyNoId_HistoryId;
        par[1] = new SqlParameter("@FamilyRole", DbType.String);
        par[1].Value= applicant.familyRole;
        par[2] = new SqlParameter("@Marryed", DbType.Int32);
        par[2].Value = applicant.marryed;
        par[3] = new SqlParameter("@WorkUnit", DbType.Int32);
        par[3].Value = applicant.workUnit;
        par[4] = new SqlParameter("@IDCard", DbType.Int32);
        par[4].Value = applicant.idCard;
        par[5] = new SqlParameter("@Income", DbType.Int32);
        par[5].Value = applicant.inCome;
        par[6] = new SqlParameter("@IsSecurity", DbType.Boolean);
        par[6].Value = applicant.isSecurity;

        bool addsucc = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(ConnString, CommandType.StoredProcedure, 
                                                                    "Insert_Applicant", par));

        return addsucc;
    }

    /// <summary>
    /// 添加家庭成员表（历史记录表）
    /// </summary>
    /// <param name="applicant"></param>
    /// <returns></returns>
    public bool AddApplicantHistory(Applicant applicant)
    {
        SqlParameter[] par = new SqlParameter[7];
        par[0] = new SqlParameter("@ApplyHistoryID", DbType.Int32);
        par[0].Value = applicant.applyNoId_HistoryId;
        par[1] = new SqlParameter("@FamilyRole", DbType.String);
        par[1].Value = applicant.familyRole;
        par[2] = new SqlParameter("@Marryed", DbType.Int32);
        par[2].Value = applicant.marryed;
        par[3] = new SqlParameter("@WorkUnit", DbType.Int32);
        par[3].Value = applicant.workUnit;
        par[4] = new SqlParameter("@IDCard", DbType.Int32);
        par[4].Value = applicant.idCard;
        par[5] = new SqlParameter("@Income", DbType.Int32);
        par[5].Value = applicant.inCome;
        par[6] = new SqlParameter("@IsSecurity", DbType.Boolean);
        par[6].Value = applicant.isSecurity;

        bool addsucc = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(ConnString, CommandType.StoredProcedure, 
                                                                    "Insert_ApplicantHistory", par));

        return addsucc;
    }

    /// <summary>
    /// 删除家庭成员表（原表）
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    public bool DeleteApplicantById(int Id)
    {
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new SqlParameter("@ID", DbType.Int32);
        par[0].Value = Id;

        bool deletesucc = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(ConnString, 
                                                                      CommandType.StoredProcedure, 
                                                                      "Delete_Applicant_By_Id", par));
        return deletesucc;
    }

    /// <summary>
    /// 删除家庭成员表（历史记录表）
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    public bool DeleteApplicantHistoryById(int Id)
    {
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new SqlParameter("@ID", DbType.Int32);
        par[0].Value = Id;

        bool deletesucc = Convert.ToBoolean(SqlHelper.ExecuteNonQuery(ConnString, 
                                                                      CommandType.StoredProcedure, 
                                                                      "Delete_ApplicantHistory_By_Id", par));

        return deletesucc;
    }

    public bool UpdateApplicant()
    {
        return true;
    }

    public bool UpdateApplicantHistory()
    {
        return true;
    }
}
